/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DSB.Model.Kaart;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 *
 * @author Gebruiker
 */
public class Waypoint extends MapDecorator {
    
    private Map _map;
    private String _name;
    private boolean _visible;
    private Coordinaat _coordinaat;
    private BufferedImage _waypointImage;
    
    /**
     *
     * @param map
     * @param name
     * @param visible
     * @param coordinate
     */
    public Waypoint(Map map, String name, boolean visible, Coordinaat coordinate)
    {
        _map = map;
        _name = name;
        _coordinaat = coordinate;
        _visible = visible;
        
                try {
            _waypointImage = ImageIO.read(new File("Resources/images/waypoint.png"));
        } catch (Exception e) {
        }
    }

    /**
     *
     * @return
     */
    @Override
    public BufferedImage DrawOnMap() {
        BufferedImage newImage = _map.DrawOnMap();
        
        BufferedImage combined = new BufferedImage(newImage.getWidth(), newImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
        
        Graphics2D g2d = combined.createGraphics();
        g2d.drawImage(newImage, 0, 0, null);
        int convlon = ConvertCoordinate(_coordinaat.getLongitude(), Enums.CoordinateDirection.HORIZONTAL);
        int convlat = ConvertCoordinate(_coordinaat.getLatitude(), Enums.CoordinateDirection.VERTICAL);
        
        if(_visible)
        {
            g2d.drawImage(_waypointImage, convlon - 10, convlat - 10,null);
        }
        
        if(_map instanceof Waypoint)
        {
            Waypoint previouswp = (Waypoint) _map;
            Coordinaat oldcoords = previouswp.getCoordinates();
            
            int oldX = ConvertCoordinate(oldcoords.getLongitude(), Enums.CoordinateDirection.HORIZONTAL);
            int oldY = ConvertCoordinate(oldcoords.getLatitude(), Enums.CoordinateDirection.VERTICAL);
            g2d.setStroke(new BasicStroke(6));
            g2d.setColor(Color.decode("#646473"));
            g2d.drawLine(oldX, oldY, convlon, convlat);          
        }
        
        return combined;
    }
    
    /**
     *
     * @return
     */
    public Coordinaat getCoordinates()
    {
        return _coordinaat;
    }
}
